package com.sos.comm
{
	import com.sos.utils.ClassUtils;
	
	public class CallSequenceStatus
	{
		
		// -------------------------------------------------------------------------------
		// CONSTANTS
		// -------------------------------------------------------------------------------		
		
		public static const READY:CallSequenceStatus			= new CallSequenceStatus(0, "READY");
		public static const RUNNING:CallSequenceStatus			= new CallSequenceStatus(1, "RUNNING");
		public static const COMPLETED:CallSequenceStatus		= new CallSequenceStatus(2, "COMPLETED");
		public static const FAILED:CallSequenceStatus			= new CallSequenceStatus(3, "FAILED");
		
		// -------------------------------------------------------------------------------
		// STATIC
		// -------------------------------------------------------------------------------
		
		private static var _initialized:Boolean = false;
		private static var _list:Vector.<CallSequenceStatus>;
		
		// Fake static constructor
		{
			// Fill the internal list
			_list = new Vector.<CallSequenceStatus>();
			_list.push(CallSequenceStatus.READY);
			_list.push(CallSequenceStatus.RUNNING);
			_list.push(CallSequenceStatus.COMPLETED);
			_list.push(CallSequenceStatus.FAILED);
			// Init!
			_initialized = true;
		}
		
		// -------------------------------------------------------------------------------
		// FIELDS
		// -------------------------------------------------------------------------------
		
		private var _id:uint;
		private var _name:String;
		
		// -------------------------------------------------------------------------------
		// CONSTRUCTORS
		// -------------------------------------------------------------------------------
		
		public function CallSequenceStatus(id:uint, name:String)
		{
			// Safe unique instance lock
			if (_initialized) throw new Error("CallSequenceStatus enum already created!");
			// Init
			_id    = id;
			_name  = name;
		}
		
		// -------------------------------------------------------------------------------
		// PROPERTIES
		// -------------------------------------------------------------------------------		
		
		public function get id():uint
		{
			return _id;
		}
		
		public function get name():String
		{
			return _name;
		}
		
		// -------------------------------------------------------------------------------
		// PUBLIC METHODS
		// -------------------------------------------------------------------------------
		
		public function toString():String
		{
			return ClassUtils.getName(this) + "." + _name;
		}
		
		// -------------------------------------------------------------------------------
		// STATIC METHODS
		// -------------------------------------------------------------------------------
		
		/**
		 * Returns the list of the names for all possible the values of CallSequenceStatus enumeration
		 * @return 
		 */
		public static function names():Array
		{
			var list:Array  = new Array;
			// Loop over values list
			for (var i:int=0; i<_list.length; i++)
			{
				list.push(_list[i].name);
			}
			return list;
		}
		
		/**
		 * Returns all possible the values for the CallSequenceStatus enumeration
		 * @return 
		 */
		public static function list():Array
		{
			var list:Array = new Array;
			// Loop over values list
			for (var i:int=0; i<_list.length; i++)
			{
				list.push(_list[i]);
			}
			return list;
		}
		
		/**
		 * Search a CallSequenceStatus by given id 
		 * @param id Id of the card type to find
		 * @return PlayerCallSequenceStatus constant for the given id, null if no CallSequenceStatus
		 * for the given id has been found
		 */		
		public static function getById(id:uint):CallSequenceStatus
		{
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].id == id) return _list[i];
			}
			throw new Error("CallSequenceStatus for id '" + id + "' unknown!");
		}
		
		/**
		 * Search a CallSequenceStatus by given name 
		 * @param name Name of the player CallSequenceStatus to find
		 * @return PlayerCallSequenceStatus constant for the given id, null if no CallSequenceStatus
		 * for the given name has been found
		 */		
		public static function getByName(name:String):CallSequenceStatus
		{
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].name == name) return _list[i];
			}
			throw new Error("CallSequenceStatus for name '" + name + "' unknown!");
		}
		
	}
}